package cn.myjerry.sort.refType;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 新闻实体类
 * @author Jerry
 *
 */

public class NewsItem implements java.lang.Comparable<NewsItem> {
	private String Title;
	private int Count;
	private Date data;
	
	public NewsItem() {
	}

	public NewsItem(String title, int count, Date data) {
		super();
		Title = title;
		Count = count;
		this.data = data;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return Title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		Title = title;
	}

	/**
	 * @return the count
	 */
	public int getCount() {
		return Count;
	}

	/**
	 * @param count the count to set
	 */
	public void setCount(int count) {
		Count = count;
	}

	/**
	 * @return the data
	 */
	public Date getData() {
		return data;
	}

	/**
	 * @param data the data to set
	 */
	public void setData(Date data) {
		this.data = data;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuffer str = new StringBuffer();
		str.append("标题：").append(this.Title);
		str.append(", 点击量").append(this.Count);
		str.append(", 发布时间：").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.data)).append("\n");
		return str.toString();
	}

	@Override
	public int compareTo(NewsItem o) {
		int result;
		result = -this.data.compareTo(o.getData());
		if(0 == result) {
			result = -this.Count - o.getCount();
			if(0 == result) {
				result = -this.Title.compareTo(o.getTitle());
			}
		}
		return result;
	}
}
